
n,k=map(int,input().split())

s=set()

count=0

for i in range(0,k):
    x,y=map(int,input().split())
    if y not in s and y!=0:
        count+=1
    s.add(x)
print(count)
